import * as amqp from 'amqplib';
const rabbitMQServer = "amqp://mingcai_mq:EUDNfpZRbhfjb8PZ@95.169.25.181";

async function produce() {
    const connection = await amqp.connect(rabbitMQServer);
    const channel = await connection.createChannel();
    const queue = 'work_queue';

    await channel.assertQueue(queue, { durable: true });

    for (let i = 0; i < 10; i++) {
        const message = `Message ${i}`;
        channel.sendToQueue(queue, Buffer.from(message), { persistent: true });
        console.log(` [x] Sent '${message}'`);
    }

    setTimeout(() => {
        connection.close();
        process.exit(0);
    }, 500);
}

produce();
